package de.koller.oceanFramework.gl.util;

import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;

public class Light {

	private float[] position = new float[] { 0f, -10f, 0f, 0 };
	private float[] diffuse = new float[] { 1, 1, 1, 1 };
	private float[] ambient = new float[] { .1f, .1f, .1f, 1 };
	private float[] specular = new float[] { 0, 0, 0, 1 };
	
	public void disableLightGL() {
		GL11.glDisable( GL11.GL_LIGHTING );
	}
	
	public void setLightGL() {
		GL11.glEnable( GL11.GL_LIGHTING );
		GL11.glEnable( GL11.GL_LIGHT0 );

		FloatBuffer fb = BufferUtils.createFloatBuffer( 16 );
		
		fb.put( ambient ).flip();
		GL11.glLight( GL11.GL_LIGHT0, GL11.GL_AMBIENT, fb );
		
		fb.put( diffuse ).flip();
		GL11.glLight( GL11.GL_LIGHT0, GL11.GL_DIFFUSE, fb );
		
		fb.put( specular ).flip();
		GL11.glLight( GL11.GL_LIGHT0, GL11.GL_SPECULAR, fb );
		
		fb.put( position ).flip();
		GL11.glLight( GL11.GL_LIGHT0, GL11.GL_POSITION, fb );
	}

	public void setLightGL(		float positionX, float positionY, float positionZ, float positionW,
								float diffuseR,  float diffuseG,  float diffuseB,  float diffuseA,
								float ambientR,  float ambientG,  float ambientB,  float ambientA,
								float specularR, float specularG, float specularB, float specularA ) {
		
		setPosition( new float[] { positionX, positionY, positionZ, positionW } );
		setDiffuse(  new float[] { diffuseR,  diffuseG,  diffuseB,  diffuseA  } );
		setAmbient(  new float[] { ambientR,  ambientG,  ambientB,  ambientA  } );
		setSpecular( new float[] { specularR, specularG, specularB, specularA } );
		
		this.setLightGL();
	}
	
	public float[] getAmbient() {
		return ambient;
	}

	public float[] getDiffuse() {
		return diffuse;
	}

	public float[] getPosition() {
		return position;
	}

	public float[] getSpecular() {
		return specular;
	}

	public void setAmbient( float[] ambient ) {
		this.ambient = ambient;
	}

	public void setDiffuse( float[] diffuse ) {
		this.diffuse = diffuse;
	}

	public void setPosition( float[] position ) {
		this.position = position;
	}

	public void setSpecular( float[] specular ) {
		this.specular = specular;
	}

}
